package cn.sad.bjsx.starter.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import cn.sad.zeroboot.auth.config.AuthInterceptor;
import cn.sad.zeroboot.auth.constants.AuthConstants;
import cn.sad.zeroboot.core.config.LogInterceptor;

/**
 * 自定义拦截器配置
 * 
 * @author sad
 *
 */
@Configuration
public class BjsxWebConfigurer implements WebMvcConfigurer {

	/**
	 * 添加拦截器（添加的顺序就是执行顺序）
	 */
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		// 注册权限认证拦截器
		registry.addInterceptor(getAuthInterceptor()).addPathPatterns("/**").excludePathPatterns("/", AuthConstants.NOT_INTERCEPTOR_PATH);
		// 注册日志追踪拦截器
		registry.addInterceptor(getLogInterceptor()).addPathPatterns("/**").excludePathPatterns("/", AuthConstants.NOT_INTERCEPTOR_PATH);
	}

	/**
	 * 将权限认证拦截器作为Bean写入配置
	 */
	@Bean
	public AuthInterceptor getAuthInterceptor() {
		return new AuthInterceptor();
	}

	/**
	 * 将日志追踪拦截器作为Bean写入配置
	 */
	@Bean
	public LogInterceptor getLogInterceptor() {
		return new LogInterceptor();
	}
}
